﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}

@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="dept-form">
                <div class="select-list">
                    <ul>
                        <li>
                            部门名称：<input type="text" name="deptName" />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add(100)" shiro:hasPermission="system:dept:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="system:dept:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-info" id="expandAllBtn">
                <i class="fa fa-exchange"></i> 展开/折叠
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="treeTable"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    var id = 0;
    $(function () {
        var options = {
            id: "treeTable",
            code: "id",
            parentCode: "parentId", // 用于设置父子关系
            uniqueId: "id",
            expandAll: false,
            expandFirst: false,
            url: "/OrganizationManage/Department/GetListJson",
            createUrl: "/OrganizationManage/Department/DepartmentForm",
            updateUrl: "/OrganizationManage/Department/DepartmentForm",
            removeUrl: "/OrganizationManage/Department/DeleteFormJson?ids={id}",
            modalName: "部门",
            columns: [
                { field: 'selectItem', radio: true },
                { field: 'departmentName', title: '部门名称', align: "left" },
                { field: 'departmentSort', title: '排序', align: "left" },
                { field: 'baseCreateTime', title: '创建时间', align: "left" },
                {
                    title: '操作', align: 'left',
                    formatter: function (value, row, index) {
                        if (row.parentId != 0) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-info  btn-xs " href="javascript:void(0)" onclick="$.operate.add(\'' + row.id + '\')"><i class="fa fa-plus"></i>新增</a> ');
                            actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-trash"></i>删除</a>');
                            return actions.join('');
                        } else {
                            return "";
                        }
                    }
                }]
        };
        $.treeTable.init(options);
    });
</script>